<?php

namespace Client\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;

class LoanController extends AbstractActionController
{
    protected $loanTable;
    protected $client_id;
    protected $loan;
    protected $loan_balance;

    public function __construct($client_id = null)
    {
        $this->client_id = $client_id;
    }

    public function getLoanTable()
    {
        if (!$this->loanTable) {
            $sm = $this->getServiceLocator();
            $this->loanTable = $sm->get('Loan\Model\LoanTable');
        }
        return $this->loanTable;
    }

    /**
     * 初始化页面渲染
     * @return array|ViewModel
     */
    public function indexAction()
    {
        $this->client_id = $this->params()->fromRoute('id', null);
        $this->loan = $this->getLoanTable()->getLoanByClientId($this->client_id);
        $this->loan_balance = $this->getLoanTable()->getLoanBalanceByClientId($this->client_id);
        $view = new ViewModel(array(
            'client_id' => $this->client_id,
            'loan' => $this->loan,
            'loan_balance' => $this->loan_balance
        ));
        return $view;
    }
}